package org.itboys.portal.web.controller.mobile;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.commons.utils.tools.ResponseManager;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.portal.dto.mobile.MobiInfoCommentResult;
import org.itboys.portal.service.manager.MobiPortalInfoCommentManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/** 
 * @author 作者 huml 
 * @version 创建时间：2016-3-30 下午3:32:11 
 * 手机端资讯评论点赞接口 
 */
@RestController
@RequestMapping("/mobile/core/portal/comment")
public class CoreMobiPortalInfoCommentController extends BaseController {

	@Autowired
	private MobiPortalInfoCommentManager commentManager;
	
	/**
	 * 发表评论
	 * 
	 * @param infoId  动态id
	 * @param parentCommentId  父评论的id  如果是直接评论资讯的话传0
	 * @param memberId  评论人id
	 * @param content  评论内容
	 * @param response
	 */
	@RequestMapping(value="/doComment", method=RequestMethod.POST)
	public void doComment(@RequestParam("infoId") Long infoId,
			@RequestParam("parentCommentId") Long parentCommentId,
			@RequestParam("content") String content,
			@RequestParam("memberId")Long memberId,
			@RequestParam(value="images", required=false)List<String> images,
			HttpServletResponse response) {
		try {
			MobiInfoCommentResult result = commentManager.doComment(
					infoId, memberId, parentCommentId, content, images);
			AjaxUtils.renderJsonporJson(response, null, ResultPageDOHelper
					.getMsgResultDO(result, CommonConstants.SUCCESS));
		} catch (Exception e) {
			logger.error("/mobile/core/portal/comment/doComment error", e);
			ResponseManager.SystemError(response, null);
		}  
	}
	
	/**
	 * 点赞
	 * @param infoId
	 * @param memberId
	 * @param response
	 */
	@RequestMapping(value="/doGood", method=RequestMethod.POST)
	public void doGood(@RequestParam("infoId") Long infoId,
			@RequestParam("memberId")Long memberId,
			HttpServletResponse response) {
		try {
			List<String> results = commentManager.doGood(infoId, memberId);
			
			AjaxUtils.renderJsonporJson(response, null, ResultPageDOHelper
					.getMsgResultDO(results, CommonConstants.SUCCESS));
		} catch (Exception e) {
			logger.error("/mobile/core/portal/comment/doGood error", e);
			ResponseManager.SystemError(response, null);
		}
	}
	
}
